package com.huatek.framework.show;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.huatek.authority.service.DataAuthorityService;
import com.huatek.framework.entity.FwAccount;
import com.huatek.framework.security.ClientInformationImpl;
import com.huatek.framework.security.ThreadLocalClient;
import com.huatek.framework.service.LoginService;

@Controller
@RequestMapping("/login.do")
public class LoginInit {
	@Autowired
	private LoginService loginService;
	@Autowired
	private DataAuthorityService dataAuthorityService;

	@RequestMapping(method = RequestMethod.POST)
	public String doLogin(HttpSession session) {
		//get user
		FwAccount account = ThreadLocalClient.get().getOperator();
		//get user authority
		account = loginService.loadUserAuthority(account.getId(),ThreadLocalClient.get().getSystemCode());
		//使用数据权限
		account.setBaseUserAuthorityData(dataAuthorityService.getUserDataAuthority(account.getId()));
		ThreadLocalClient.get().setOperator(account);


		session.setAttribute(ClientInformationImpl.LOGIN_ACCOUNT, account);
		return "page.welcome";
	}
}
